package cn.edu.hhu.teacher;

import cn.edu.hhu.teacher.bean.Teacher;
import cn.edu.hhu.teacher.service.TeacherService;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;

@WebServlet("/teacher/info")
public class InfoServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Teacher teacher = (Teacher) request.getSession().getAttribute("teacher");
        String department = request.getParameter("department");
        if (department != null) {
            teacher.setDepartment(department);
        }
        String pwd = request.getParameter("pwd");
        if (pwd != null && !pwd.equals("")) {
            teacher.setPwd(pwd);
        }
        TeacherService teacherService = new TeacherService();
        teacherService.update(teacher);
        request.getRequestDispatcher("/WEB-INF/view/teacher/info.jsp").forward(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.getRequestDispatcher("/WEB-INF/view/teacher/info.jsp").forward(request, response);
    }
}
